// Vue3 源码中的泛型约束
class ObjectRefImpl<T extends object, K extends keyof T> {
    public readonly __v_isRef = true;
    constructor(public readonly obj: T, public readonly key: K) {}

    get value() {
        return this.obj[this.key];
    }

    set value(newValue: T[K]) {
        this.obj[this.key] = newValue;
    }
}

type ObjTyp = { username: string, age: number };
type KeysTyp<K> = K extends keyof ObjTyp ? K : never;
type TestKeysTyp = KeysTyp<"username" | "age">
const obj = new ObjectRefImpl<ObjTyp, "age">({username: "lisi", age: 18}, "age");
console.log("obj.value:", obj.value);

export {}
